package com.yuerlive.paperplane.database;

import android.arch.persistence.room.TypeConverter;
import android.arch.persistence.room.TypeConverters;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yuerlive.paperplane.data.source.DoubanMomentNewsThumbs;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Admin on 2017/10/13.
 */

public class DoubanTypeConverters {
    @TypeConverter
    public static String thumbListToString(List<DoubanMomentNewsThumbs> thumbs){
       return  new Gson().toJson(thumbs);
    }
    @TypeConverter
    public static List<DoubanMomentNewsThumbs> stringToThumbList(String string){
        Type listType =new TypeToken<ArrayList<DoubanMomentNewsThumbs>>(){}.getType();
        return new Gson().fromJson(string,listType);
    }
}
